#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	int fds[2];
	int ret=pipe(fds);
	if(fork<0){
		perror("perror");
		return 1;
	}
	if(fork()==0){//子进程向管道写数据
		close(fds[0]);
		char *buf="hello";
		while(1){
			sleep(1);
			write(fds[1],buf,strlen(buf));
		}
		close(fds[1]);
	}

	else{//父进程读数据
		close(fds[1]);
		char buf[1024]={0};
		int s=0;
		while(1){
			s=read(fds[0],buf,sizeof(buf)-1);
			printf("%s\n",buf);
		}
		close(fds[0]);
	}
	return 0; 
}
